package com.apress.messaging.domain;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import com.apress.messaging.server.RestTemplateClient;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;

@Component
@ConfigurationProperties(prefix = "customerapi")
public class CustomerApi {

	private	String	rootUri;

	public String getRootUri() {
		return rootUri;
	}

	public void setRootUri(String rootUri) {
		this.rootUri = rootUri;
	}
	/**
	 * 调用接口像数据库中添加消息
	 * @param message
	 * @return
	 */
	public	String	sendMsg(String message){
		JSONObject jsonObject = JSON.parseObject(message);
		String	petUser	=	jsonObject.getString("petUser");
		String	seat	=	jsonObject.getString("seat");
		String	postMessages	=	jsonObject.getString("postMessages");
		JSONObject  paramMap  =   new JSONObject();
        paramMap.put("petUser", petUser);
        paramMap.put("seat", seat);
        paramMap.put("postMessages", postMessages);
        
        return	HttpUtil.post(rootUri+"/js/messageses/sendMsg",paramMap);
	}
	public	cn.hutool.json.JSONObject	rg(String formUser,String toUser,String	postMessages) {
		String	rootUri	=	"http://192.168.0.139:80/js/messageses/sendMsg";
        //restTemplateClient.setRootUri(rootUri);
		JSONObject  paramMap  =   new JSONObject();
        paramMap.put("formUser", formUser);
        paramMap.put("toUser", toUser);
        paramMap.put("postMessages", postMessages);
        
        String result= HttpUtil.post(rootUri,paramMap);
		return	JSONUtil.parseObj(result);
	}
}
